

-- Namespace
	local _,mod = ...


-- Object reference
	local units = mod.units
	local resolve = mod.resolve


-- Name
	local care = mod:unitevent_care('name')
	if care then
		local function NAME(unit)
			if not care[unit] then return end
			local u = units[unit]
			
			local name,realm = UnitName(unit)
			if not name then
				name = unit
			end
			
			u:Update('name',name,realm)
		end
		
		mod:event_register('UNIT_NAME_UPDATE',NAME)
		
		resolve[#resolve+1] = NAME
	end


-- Level
	local care = mod:unitevent_care('level')
	if care then
		local function LEVEL(unit)
			if not care[unit] then return end
			local u = units[unit]
			
			local level = UnitLevel(unit)
			local clas = UnitClassification(unit)
			
			if level == -1 then
				level = nil
			end
			
			u:Update('level',level,clas)
		end
		
		mod:event_register('UNIT_LEVEL',LEVEL)
		mod:event_register('UNIT_CLASSIFICATION_CHANGED',LEVEL)
		
		mod:event_register('PLAYER_LEVEL_UP',function()
			LEVEL('player')
		end)
		
		resolve[#resolve+1] = LEVEL
	end


-- Class
	local care = mod:unitevent_care('class')
	if care then
		local function CLASS(unit)
			if not care[unit] then return end
			local u = units[unit]
			
			u:Update('class',UnitClass(unit))
		end
		
		mod:event_register('UNIT_NAME_UPDATE',CLASS)
		
		resolve[#resolve+1] = CLASS
	end


-- Experience
	local care = mod:unitevent_care('experience')
	if care and care['player'] then
		local function EXPERIENCE(unit)
			if unit ~= 'player' then return end
			
			local u = units[unit]
			
			local level = UnitLevel(unit)
			if level == MAX_PLAYER_LEVEL or IsXPUserDisabled() then
				u:Update('experience',nil)
			else
				u:Update('experience',UnitXP(unit),UnitXPMax(unit),GetXPExhaustion())
			end
		end
		
		mod:event_register('PLAYER_XP_UPDATE',function()
			EXPERIENCE('player')
		end)
		mod:event_register('PLAYER_LEVEL_UP',function()
			EXPERIENCE('player')
		end)
		mod:event_register('PLAYER_ENTERING_WORLD',function()
			EXPERIENCE('player')
		end)
	end


-- Combat
	local care = mod:unitevent_care('combat')
	if care and care['player'] then
		mod:event_register('PLAYER_REGEN_DISABLED',function()
			local u = units['player']
			u:Update('combat',true)
		end)
		
		mod:event_register('PLAYER_REGEN_ENABLED',function()
			local u = units['player']
			u:Update('combat',false)
		end)
	end


-- Connection
	local care = mod:unitevent_care('connected')
	if care then
		local function CONNECTED(unit)
			if not care[unit] then return end
			local u = units[unit]
			
			u:Update('connected',UnitIsConnected(unit))
		end
		
		mod:event_register('UNIT_CONNECTION',CONNECTED)
		
		resolve[#resolve+1] = CONNECTED
	end


-- Role
	local care = mod:unitevent_care('role')
	if care then
		local function ROLE(unit)
			if not care[unit] then return end
			local u = units[unit]
			
			local role = UnitGroupRolesAssigned(unit)
			if role == 'NONE' then
				role = nil
			end
			
			u:Update('role',role)
		end
		
		mod:event_register('ROLE_CHANGED_INFORM',function()
			local unit
			for i = 1,4 do
				unit = ('party%d'):format(i)
				ROLE(unit)
			end
			ROLE('player')
		end)
		
		resolve[#resolve+1] = ROLE
	end
